﻿using System.Web;

namespace netaddICTs.Umb.ProtectedMedia.Business.IO {

    internal class VirtualDirectoryStorageImpl : StorageImpl, IFileStorage {
    
        public HttpContext Context { get; set; }

        public VirtualDirectoryStorageImpl(HttpContext context, string path)
            : base(path) {
            Context = context;
        }

        #region IFileStorage Members

        public bool Create(int mediaNodeId, HttpPostedFile postedFile) {
            return Create(string.Concat(Context.Server.MapPath(Path), PathSeparator, mediaNodeId), postedFile);
        }

        public bool Delete(int mediaNodeId) {
            return Delete(string.Concat(Context.Server.MapPath(Path), PathSeparator, mediaNodeId));
        }

        public long CalculateBytes(int mediaNodeId, HttpPostedFile postedFile) {
            return
                CalculateBytes(string.Concat(Context.Server.MapPath(Path), PathSeparator, mediaNodeId, PathSeparator,
                                             postedFile.FileName));
        }

        public override string BuildFilename(int mediaNodeId, string filename) {
            return string.Concat(Context.Server.MapPath(Path), PathSeparator, mediaNodeId, PathSeparator, filename);
        }

        #endregion
    }
}
